Skip to content

feat: filter search for commit change type #1381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Yusin0903
Copy link

@Yusin0903 Yusin0903 commented Apr 5, 2025

Description

Added search filter functionality to commit type selection in Conventional Commits. This allows users to quickly find commit types by typing part of the type name or description, enhancing user experience especially when working with many commit types.

Changes Made

  1. Added use_search_filter: True to enable search filtering in the commit type selection.
  2. Set use_jk_keys: False to prevent conflicts with search functionality (as j/k keys can be part of the search term).
  3. Because the interaction questionary can not test directly so I test to verify search filter functionality and parameter works correctly.
  4. Added newline at the end of file to comply with PEP 8 standards.

Checklist

  • Add test cases to all the changes you introduce
  • Run poetry all locally to ensure this change passes linter check and test
  • Test the changes on the local machine manually
  • Update the documentation for the changes

Expected behavior

When a user types characters during commit type selection, the list of options is filtered to show only those containing the typed characters. For example, typing "fix" will show the item that contains "fix" .

Steps to Test This Pull Request

  1. Run cz commit to start the commit process
  2. When the commit type selection appears, type what you want to search. eg: "fix"
  3. Verify that the list filters to show the all "fix" items
  4. Try other search terms to confirm filtering works as expected

Additional context

@Yusin0903 Yusin0903 changed the title Feat filter search for commit change type feat: filter search for commit change type Apr 5, 2025
@Lee-W Lee-W force-pushed the feat-filter-search-for-commit-change-type branch from 4dd1521 to 5c52c3d Compare April 6, 2025 04:07
Copy link

codecov bot commented Apr 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.55%. Comparing base (120d514) to head (c0b1e05).
Report is 585 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1381      +/-   ##
==========================================
+ Coverage   97.33%   97.55%   +0.21%     
==========================================
  Files          42       57      +15     
  Lines        2104     2656     +552     
==========================================
+ Hits         2048     2591     +543     
- Misses         56       65       +9     
Flag Coverage Δ
unittests 97.55% <ø> (+0.21%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines 49 to 50
"use_search_filter": True,
"use_jk_keys": False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know whether we should set it as the default, probably not for v4. I would suggest making it configurable. Also, this now only works for conventional_commits, we would like it to work for all cz rules. Following up with this discussion, we probably could make the whole questionary behavior configurable, but that could be another PR

Copy link
Author

@Yusin0903 Yusin0903 Apr 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! I will modify the search function to work for all cz rules. As for making it configurable, we can open another issue for that. Does that sound good?

Copy link
Member

@Lee-W Lee-W Apr 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably say we should make it configurable first to retain the current behavior and let those who want to play with it opt in

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Lee-W,

I have tested the search filter functionality using the configuration approach:

[[tool.commitizen.customize.questions]]
type = "list"
name = "change_type"
message = "Select the type of change you are committing"
use_search_filter = true
use_jk_keys = false

It works as expected, so I've:

  • Removed the modifications to conventional_commits.py
  • Added documentation for the feature in customization.md
  • Added test cases to verify the functionality
    The search filter can now be enabled through configuration without modifying the core code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but if we do it this way, doesn't that mean we won't be able to use it in other cz rules?

Copy link
Author

@Yusin0903 Yusin0903 Apr 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to ask if cz_empty and cz_no_default imply that JIRA and conventional commits can also be customized? If that's the case, should we address this in the current issue?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JIRA and conventional commits can also be customized?

These two are somewhat customizable, but just not at the same level as cz_customize.

e.g., they have the fixed set of questions that cannot yet be customized at this moment but some of the behavior can still be changed by our config file

We don't need to do cz_empty in this PR. but we might want to pass these 2 options into all cz rules

Copy link
Author

@Yusin0903 Yusin0903 Apr 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is what you meant,
But I added a question_type field in Settings, where users can choose "select" or "list".
This solution works based on my testing and fulfills the spec.

By the way, I want to ask what would the jira rule be like?
jira rule does not have list now.

.cz.toml

[tool.commitizen]
name = "cz_conventional_commits"
tag_format = "$version"
version_scheme = "semver"
version = "0.0.1"
update_changelog_on_bump = true
major_version_zero = true
question_type = "select"

conventional_commits.py

def __init__(self, config: BaseConfig):
        super().__init__(config)
        self.question_type = self.config.settings.get("question_type", "list")

    def questions(self) -> Questions:
        # Default questions
        questions: Questions = [
            {
                "type": self.question_type,
                "name": "prefix",
                "message": "Select the type of change you are committing",
                ...
         if questions[0]["type"] == "select":
            questions[0].update({"use_search_filter": True, "use_jk_keys": False})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait...

I thought we only need use_search_filter and use_jk_keys to config this kind of search on questions that is select or list?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thought is that the user only needs to set the type.
Since select type requires additional options like:

"use_search_filter": true,
"use_jk_keys": false

but list does not,
I apply these settings in code when the type is select,
so the user doesn't need to configure them manually.

Do you think config these two is a better way ?

@Yusin0903 Yusin0903 force-pushed the feat-filter-search-for-commit-change-type branch from 5c52c3d to 2f233d8 Compare April 7, 2025 18:20
@Yusin0903
Copy link
Author

Yusin0903 commented Apr 10, 2025

Hi @Lee-W,

I have tested the search filter functionality using the configuration approach:

[[tool.commitizen.customize.questions]]
type = "list"
name = "change_type"
message = "Select the type of change you are committing"
use_search_filter = true
use_jk_keys = false

It works as expected, so I've:

  • Removed the modifications to conventional_commits.py
  • Added documentation for the feature in customization.md
  • Added test cases to verify the functionality
    The search filter can now be enabled through configuration without modifying the core code.

@Lee-W
Copy link
Member

Lee-W commented Apr 13, 2025

Hey @Yusin0903 , just noticed the CI is failing. Could you please take a look? Thanks 🙂

@Yusin0903 Yusin0903 force-pushed the feat-filter-search-for-commit-change-type branch from 2f233d8 to c0b1e05 Compare April 14, 2025 02:11
@woile
Copy link
Member

woile commented Apr 14, 2025

We could also deprecate cz_customize, and just use [tool.commitizen.customize] to override the existining cz based on the name. Example: if you have set cz_conventional_commits, then anything in tool.commitizen.customize would override cz_conventional_commits

@Lee-W
Copy link
Member

Lee-W commented Apr 15, 2025

We could also deprecate cz_customize, and just use [tool.commitizen.customize] to override the existining cz based on the name. Example: if you have set cz_conventional_commits, then anything in tool.commitizen.customize would override cz_conventional_commits

Yep, this is a fantastic idea!

@Lee-W Lee-W mentioned this pull request Apr 15, 2025
@Yusin0903 Yusin0903 force-pushed the feat-filter-search-for-commit-change-type branch from 2489e23 to c0b1e05 Compare April 15, 2025 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants